package com.qf.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.mapper.OrderMapper;
import com.qf.pojo.Order;
import com.qf.service.OrderService;
import com.qf.pojo.VoOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;


    @Override
    public Boolean addOrder(Order order) {
        int in= orderMapper.subOrder(order);
        if (in>0){
            return true;
        }
        return false;
    }

    @Override
    public Map<String, Object> findAll(Integer page, Integer limit) {

        //在调用mapper之前先执行分页插件
        PageHelper.startPage(page,5);
        //调用方法
        List<VoOrder> list = orderMapper.selectAll();
        Map<String,Object> map = new HashMap<>();


       PageInfo pageInfo = new PageInfo(list);
//        System.out.println(pageInfo.getTotal());

        map.put("total",pageInfo.getTotal());
        map.put("rows",list);
        return map;
    }

    @Override
    public Boolean deleteOrder(Integer oid) {
        int in = orderMapper.deleteOrderById(oid);
        if (in>0){
            return true;
        }
        return false;
    }
}
